package main

import (
	"fmt"
	"math/rand"
	"store/libs/container"
	"sync"
	"time"
)

func main() {
	//file, _ := helper.FOpen("/tmp/bf.bin", "a+", 0775)
	bm := container.NewBitmap(nil)

	//如果以文件为存储介质，Close会自动删除文件以释放资源，如不想删除文件，注释掉就可以。
	/*defer func() {
		err := bm.Close()
		if err != nil {
			fmt.Println(err.Error())
		}
	}()*/

	nums := 1000000
	w := sync.WaitGroup{}
	w.Add(nums)

	start := time.Now()

	for index := 0; index < nums; index++ {
		value := int(rand.Uint32())
		go func(wa *sync.WaitGroup, in int) {
			_, err := bm.ValueExists(uint32(in))
			if err != nil {
				fmt.Println(err.Error())
			}
			wa.Done()
		}(&w, value)
	}

	w.Wait()
	fmt.Printf("%d次并发读，历时：%s\n", nums, time.Now().Sub(start).String())
}
